<template>
	<div class="spike">
		<!-- 顶部区域 -->
		<header class="spike-top">
			<!-- 左边区域 -->
			<div class="top-left">
				<!-- 镂空区域 -->
				<div class="swiper top-left-swiper">
					<ol class="swiper-wrapper">
						<li class="swiper-slide" v-for="item in spikeList" :key="item.id">
							<nav class="title-time">
								<strong>限时特惠</strong>
								<label v-html="item.dateHtml"></label>
							</nav>
							<div class="contain">
								<article>
									<h4>仅限{{item.num}}个</h4>
									<img :src="item.imgURL"/>
									<p>{{item.city}}</p>
								</article>
								<aside>
									<h3>{{item.title}}</h3>
									<p>
										￥<strong>{{item.price}}</strong>起<em>{{item.oldprice}}</em>
									</p>
								</aside>
							</div>
						</li>
					</ol>
				</div>
			</div>
			<!-- 右边区域 -->
			<div class="top-right">
				<article>
					<h3>
						新品推荐
						<i class="iconfont icon-youjiantou"></i>
					</h3>
					<aside>
						<h4>{{newsList.title}}</h4>
						<p>
							￥<strong>{{newsList.price}}</strong>起
						</p>
					</aside>
				</article>
				<article>
					<h3>
						爆品线路
						<i class="iconfont icon-youjiantou"></i>
					</h3>
					<aside>
						<h4>{{hotList.title}}</h4>
						<p>
							￥<strong>{{hotList.price}}</strong>起
						</p>
					</aside>
				</article>
			</div>
		</header>
		<!-- 底部区域 -->
		<ul class="spike-bottom">
			<li>
				<router-link to="/">
					<h3>宝藏小城</h3>
					<p>挖掘小城魅力</p>
				</router-link>
			</li>
			<li>
				<router-link to="/">
					<h3>秋色播报</h3>
					<p>赏秋好去处</p>
				</router-link>
			</li>
			<li>
				<router-link to="/">
					<h3>侠魅榜</h3>
					<p>每月最佳游记</p>
				</router-link>
			</li>
		</ul>
	</div>
</template>

<script>
import Swiper , {
	Autoplay
} from 'swiper';

// //swiper组件应用配置
Swiper.use([Autoplay]);

export default {
	name:'Spike',
	props:['propspikeList','propnewsList','prophotList'],
	data(){
		return {
			spikeList : [],
			newsList : {},
			hotList : {}
		}
	},
	watch:{
		propspikeList(){
			this.spikeList = this.propspikeList.spikeList;
			if(this.spikeList.length>0){
				//立即调用刷新倒计时方法
				this.reloadTime();
				//每隔1秒调用一次刷新倒计时方法
				setInterval(this.reloadTime,1000);
			}
			new Swiper('.top-left-swiper' , {
				//循环播放
				// loop:true,
				//设置播放项[时间不停止，手指经过不暂停自动]
				autoplay:{
					delay : 3000,
					stopOnLastSlide : false,
					disableOnInteraction:false,
				}
			})
			
		},
		propnewsList(){
			this.newsList = this.propnewsList;
		},
		prophotList(){
			this.hotList = this.prophotList;
		}
	},
	methods:{
		//刷新倒计时
		reloadTime(){
			//循环设置对象内新添加的dateHtml属性为最新倒计时
			for(let item of this.spikeList){
				//调用计算属性过滤时间
				item.dateHtml = this.fiterTimes(item.times);
			}
		}
	},
	computed:{
		fiterTimes(){
			return (x)=>{
				//获取当前系统当前的时间戳
				let now = new Date().getTime();
				//计算两个时间戳的差值
				let setupTime  = x - now;
				if(setupTime<0){
					return "0天<i>00</i>:<i>00</i>:<i>00</i>";
				}
				//计算提取天数+小时+分钟+秒数
				let dnum = Math.floor(setupTime / (24*60*60*1000));
				let hnum = Math.floor(setupTime / (60*60*1000)%24);
				let mnum = Math.floor(setupTime / (60*1000) %60);
				let snum = Math.floor(setupTime / 1000%60);
				if(hnum<=9) hnum='0'+hnum;
				if(mnum<=9) mnum='0'+mnum;
				if(snum<=9) snum='0'+snum;
				return `${dnum}天<i>${hnum}</i>:<i>${mnum}</i>:<i>${snum}</i>`;
			}
		},
	}
}
</script>

<style scoped>
a{
	text-decoration: none;
	color: black;
}
/* 最外层 */
.spike{
	width: 95%;
	margin: 0.5rem auto;
	height: 7.6rem;
}
/* 顶部 */
.spike-top{
	height: 65%;
	width: 100%;
	display: flex;
	justify-content: center;
}
/* 顶部的左边 */
.spike-top .top-left{
	width: 51%;
	height: 100%;
	background: url(../../../assets/img/spike/spike-bg04.png);
	background-repeat: no-repeat;
	background-size: 100% 100%;
}
/* 滑动区域的样式 */
.top-left .top-left-swiper{
	width: 90%;
	height: 100%;
	margin: 0 auto;
}
.top-left .top-left-swiper ol{
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
}
.top-left .top-left-swiper ol li{
	height: 100%;
	width: 100%;
}
.top-left .top-left-swiper ol .title-time{
	line-height: 0.8rem;
	color: white;
	font-size: 0.4rem;
	display: flex;
}
.top-left-swiper .title-time strong{
	font-weight: bold;
	width: 40%;
}
.top-left-swiper .title-time label{
	font-size: 0.25rem;
	flex: 1;
	text-align: right;
	white-space: nowrap;
}
.top-left-swiper .title-time label:deep(i){
	color: #ff8684;
	margin: 0 0.08rem;
	display: inline-block;
	line-height: 0.38rem;
	width: 0.45rem;
	height: 0.4rem;
	text-align: center;
	border-radius: 0.1rem;
	background-color: white;
}
/* 图片区域 */
.top-left-swiper .contain{
	height: 4rem;
	width: 100%;
	border-radius: 0.2rem;
	background-color: white;
} 
.top-left-swiper .contain article{
	position: relative;
	height: 60%;
	background-color: #FF8684;
}
.top-left-swiper .contain article img{
	width: 100%;
	height: 100%;
	border-top-left-radius: 0.2rem;
	border-top-right-radius: 0.2rem;
}
.top-left-swiper .contain article h4{
	position: absolute;
	left: 0;
	top: 0;
	background: linear-gradient(#ffe414,#e6c81a);
	padding: 0.08rem 0.15rem;
	border-top-left-radius: 0.2rem;
	border-bottom-right-radius: 0.2rem;
}
.top-left-swiper .contain article p{
	position: absolute;
	left: 0;
	top: 70%;
	padding: 0.1rem 0.25rem;
	color: white;
	border-radius: 0 0.2rem 0.2rem 0;
	background-color: rgba(0,0,0,.6);
}
.top-left-swiper .contain aside{
	height: 35%;
	padding: 0.1rem;
	border-radius: 0 0 0.2rem 0.2rem;
}

.top-left-swiper .contain aside h3{
	font-size: 0.35rem;
	font-weight: bold;
	line-height: 0.4rem;
	overflow: hidden;
	height: 0.78rem;
	display: -webkit-box;/* 转换为盒子 */
	-webkit-line-clamp: 2;/* 跟高度有关 */
	-webkit-box-orient: vertical;/* 超出盒子外的文本用省略号代替 */
}
.top-left-swiper .contain aside p{
	font-size: 0.35rem;
	line-height: 0.7rem;
	color: coral;
	font-weight: bold;
}
.top-left-swiper .contain aside p em{
	color: #737373;
	padding-left: 0.2rem;
	font-size: 0.2rem;
	text-decoration: line-through;
}

/* 顶部的右边 */
.spike-top .top-right{
	width: 50%;
	height: 100%;
	background: url(../../../assets/img/spike/spike-bg05.png);
	background-repeat: no-repeat;
	background-size: 100% 100%;
}
.top-right article{
	width: 90%;
	height: 49%;
	margin: 0 auto;
}
.top-right article h3{
	color: white;
	line-height: 0.8rem;
	font-size: 0.4rem;
	font-weight: bold;
}
.top-right article aside{
	width: 100%;
	background-color: white;
	border-radius: 0.2rem;
	text-indent: 0.2rem;
}
.top-right article aside h4{
	font-size: 0.4rem;
	font-weight: bold;
	line-height: 0.8rem;
}
.top-right article aside p{
	line-height: 0.5rem;
	color: #FF7F50;
	font-size: 0.3rem;
}
.top-right article aside p strong{
	font-size: 0.4rem;
	font-weight: bold;
}
.top-right article:first-child{
	border-bottom: 0.03rem solid white;
}
/* 底部样式 */
.spike-bottom{
	height: 30%;
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-top: 0.3rem;
}
.spike-bottom li{
	width: 32%;
	height: 100%;
	overflow: hidden;
	background-size: 100% 100%;
}
.spike-bottom li h3{
	line-height: 0.8rem;
	font-size: 0.35rem;
	font-weight: bold;
	text-indent: 0.3rem;
}
.spike-bottom li p{
	font-size: 0.25rem;
	text-indent: 0.3rem;
	color: gray;
}
.spike-bottom li:first-child{
	border-radius: 0.3rem 0 0 0.3rem;
	background-image: url(../../../assets/img/spike/spike-bg01.jpg);
}
.spike-bottom li:nth-child(2){
	background-image: url(../../../assets/img/spike/spike-bg02.png);
}
.spike-bottom li:last-child{
	border-radius: 0 0.3rem 0.3rem 0;
	background-image: url(../../../assets/img/spike/spike-bg03.png);
}
</style>
